package com.neusoft.ysu.elm99.controller;

import com.neusoft.ysu.elm99.entity.CommonResult;
import com.neusoft.ysu.elm99.entity.Dept;
import com.neusoft.ysu.elm99.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
//5
@RestController
@CrossOrigin
@RequestMapping("/d")
public class DeptController {
    @Autowired
    DeptService deptService;

    @Value("${abc.xyz}")
    private int index;


    @GetMapping("/q/all")
    public CommonResult findAll(){

        return deptService.findAll();
    }
    @GetMapping("/del/{depnum}")
    public CommonResult delete(@PathVariable int depnum){
        return deptService.delete(depnum);
    }

    @GetMapping("/m1")
    public String m1(){
        System.out.println("index:"+index);
        return "不太ok";
    }
    @GetMapping("/q/byid/{deptnum}")
    public CommonResult findById(@PathVariable int deptnum){
        //需要依赖一个service层来返回CommonResult
        return deptService.findById(deptnum);
    }

    @PutMapping("/add")
    public CommonResult addDept(@RequestBody Dept dept){
        return deptService.addDept(dept);
    }
    @PostMapping("/mod")
    public CommonResult modDept(@RequestBody Dept dept){
        return deptService.modDept(dept);
    }
}
